﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s = textBox1.Text;
            if (s.Length!=1)
            {
                MessageBox.Show("只能输入1个字符!");
                textBox1.Text="";
                textBox1.Focus();
                return;
            }

            char c = s[0];
            int loopCount, baseNum;
            if (Char.IsNumber(c)) baseNum=49;     //数字1从49开始
            else if (Char.IsUpper(c)) baseNum = 65;   //大写字母65开始
            else if (Char.IsLower(c)) baseNum = 97;   //小写字母97开始
            else
            {
                MessageBox.Show("您输入的字符不合法，只能是大小写字母或数字1-9！");
                textBox1.Text = "";
                textBox1.Focus();
                return;
            }
            loopCount = c - baseNum+1;            //计算循环次数
            label2.Text = "";
            for (int i = 0; i < loopCount; i++)
            {
                for (int j = loopCount; j >i+1; j--)
                {
                    label2.Text += " ";
                    //先输出当前行的空格：第i行有loopCount-i个
                }
                for (int k = 0; k < 2*i+1; k++)
                {
                    label2.Text += (char)(baseNum+i);
                }
                //再输出当前行的字符：第i行有2i+1个
                label2.Text +="\r\n";
            }
        }

private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            label2.Text="输出结果";
        }
    }
}